package org.example;

/**
 * Hello world!
 *
 */

import service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        // 确保配置文件路径正确
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        // 使用正确的bean名称和类型
        OrderService orderService = context.getBean("orderService", OrderService.class);

        System.out.println("=== 开始测试 AOP 功能 ===");

        testAdd(orderService);
        testDelete(orderService);
        testFind(orderService);
    }

    private static void testAdd(OrderService orderService) {
        System.out.println("\n=== 测试 add 方法 ===");
        try {
            orderService.add("iPhone", 2);
        } catch (Exception e) {
            System.out.println("add 方法执行失败: " + e.getMessage());
        }
    }

    private static void testDelete(OrderService orderService) {
        System.out.println("\n=== 测试 delete 方法 ===");
        try {
            orderService.delete("iPhone");
        } catch (Exception e) {
            System.out.println("delete 方法执行失败: " + e.getMessage());
        }
    }

    private static void testFind(OrderService orderService) {
        System.out.println("\n=== 测试 find 方法 ===");
        try {
            int quantity = orderService.find("iPad");
            System.out.println("查询结果数量: " + quantity);
        } catch (Exception e) {
            System.out.println("find 方法执行失败: " + e.getMessage());
        }
    }
}